package com.xmb.wechat.delegate;

import android.app.Activity;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;

import com.blankj.utilcode.util.SizeUtils;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.squareup.picasso.Picasso;
import com.xmb.wechat.R;
import com.xmb.wechat.baserecyclerview.BaseRecyclerViewManager;
import com.xmb.wechat.bean.BankCardBean;
import com.xmb.wechat.definterface.onBankCardChooseCallBack;
import com.yqritc.recyclerviewflexibledivider.HorizontalDividerItemDecoration;

import java.util.ArrayList;

/**
 * @Author lijiangop
 * @CreateTime 2020/4/17 08:56
 */
public class BankCardDelegate extends BaseRecyclerViewManager {

    private onBankCardChooseCallBack callBack;

    public BankCardDelegate(Activity activity, onBankCardChooseCallBack callBack) {
        super(activity);
        this.callBack = callBack;
    }

    @Override
    public BaseQuickAdapter initAdapter() {
        return new BaseQuickAdapter<BankCardBean, BaseViewHolder>(R.layout.item_bank_card, new ArrayList<>()) {
            @Override
            protected void convert(BaseViewHolder helper, BankCardBean item) {
                helper.setText(R.id.tv_content, item.getBankName() + "(" + item.getBankNumber() + ")");
                Picasso.get().load(item.getAvatar()).error(R.drawable.default_image).into((ImageView) helper.getView(R.id.iv_icon));
                helper.itemView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        if (callBack != null)
                            callBack.onClick(item);
                    }
                });
                helper.itemView.setOnLongClickListener(new View.OnLongClickListener() {
                    @Override
                    public boolean onLongClick(View v) {
                        if (callBack != null)
                            callBack.onLongClick(item);
                        return false;
                    }
                });
            }
        };
    }

    @Override
    protected RecyclerView.ItemDecoration getItenDecoration() {
        return new HorizontalDividerItemDecoration.Builder(context).size(SizeUtils.dp2px(1f)).color(ContextCompat.getColor(context, R.color.black_10)).build();
    }
}
